package com.linkage.jz.bankruptcy.activity.Project.ZQUser;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.linkage.jz.bankruptcy.BankruptcyApp;
import com.linkage.jz.bankruptcy.R;
import com.linkage.jz.bankruptcy.activity.Main.CarryOutListActivity;
import com.linkage.jz.bankruptcy.activity.Main.DateCalcActivity;
import com.linkage.jz.bankruptcy.activity.Main.PenaltyCalcActivity;
import com.linkage.jz.bankruptcy.activity.Main.RateCalcActivity;
import com.linkage.jz.bankruptcy.activity.Person.PersonSettingReadMeActivity;
import com.linkage.jz.bankruptcy.base.BaseActivity;
import com.linkage.jz.bankruptcy.event.RefreshEvent;
import com.linkage.jz.bankruptcy.net.BaseSubscriber;
import com.linkage.jz.bankruptcy.net.Network;
import com.linkage.seapeak.activity.message.ZQMultiSelectActivity;
import com.linkage.seapeak.pojo.CrediterUser;
import com.mob.wrappers.AnalySDKWrapper;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import uk.co.senab.photoview.PhotoView;

import static com.linkage.jz.bankruptcy.event.RefreshEvent.SHOWFINISH;


/**
 * A login screen that offers login via email/password.
 */
public  class ShowMultiDataActivity extends BaseActivity implements OnClickListener{
    private static final String TAG = PersonSettingReadMeActivity.class.getSimpleName();

    @Override
    public void initData() {

    }

    @Override
    public void setListener() {

        top_back.setOnClickListener(this);

    }

    static Boolean committee;
    static  Boolean onlineStatus;
    static Boolean kindTax;
    static Boolean kindGuarantee;
    static Boolean kindOther;
    static Boolean kindOrdinary;
    static Double minAmountDeclared;
    static Double maxAmountDeclared;
    static Double minConfirmAmount;
    static Double maxConfirmAmount;
    static String processStatus;
    static String mProjectId;

    static String mSelectType;
    static String mCreditorIds;
    int pageNo = 1;
    int pageSize = 20;
    String type = "0";

    TextView msg1,msg2,msg3,msg4,msg5,msg6,msg7,msg8,msg9,msg10,msg11,msg12;

    Button tv_1,tv_2;
    boolean canSelectAlready = true;

    String form = "";
    /**
     * 开启页面
     * @param context
     * @param projectId
     */
    public static void start(Context context, String projectId,Boolean i_committee,Boolean i_online,Boolean i_kindTax,
                             Boolean i_kindGuarantee,Boolean i_kindOther,Boolean i_kindOrdinary,Double i_minAmountDeclared,
                             Double i_maxAmountDeclared,Double i_minConfirmAmount,Double i_maxConfirmAmount,String i_processStatus,
                             String selectType, String creditorIds){
        Intent intent = new Intent(context, ShowMultiDataActivity.class);

        mProjectId = projectId;

        committee = i_committee;

        onlineStatus = i_online;
        kindTax = i_kindTax;
        kindGuarantee = i_kindGuarantee;
        kindOther = i_kindOther;
        kindOrdinary = i_kindOrdinary;
        minAmountDeclared = i_minAmountDeclared;
        maxAmountDeclared = i_maxAmountDeclared;
        minConfirmAmount =i_minConfirmAmount;
        maxConfirmAmount = i_maxConfirmAmount;
        processStatus = i_processStatus;
        mSelectType = selectType;
        mCreditorIds  = creditorIds;

        context.startActivity(intent);
    }




    @Override
    public void initTitle() {
        top_title = findViewById(R.id.top_title);
//        if(mType ==1) {
//            top_title.setText("法定代表人身份证明模板");
//        }else{
            top_title.setText("统计信息");
//        }
        top_mune.setVisibility(View.INVISIBLE);

    }

    @Override
    public void initView() {

    }


    TextView top_title;
    PhotoView image;
    Button top_back,top_mune;

    private static int  mType = 1;

    public static void start(Context context,int type) {
        mType = type;
        Intent intent = new Intent(context, ShowMultiDataActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        setContentView(R.layout.activity_show_multidata);

        initview();
        getList();
        super.onCreate(savedInstanceState);
    }

    //初始化视图
    private void initview() {
        //登录层、下拉层、其它登录方式层



        top_back = findViewById(R.id.top_back);
        top_mune = findViewById(R.id.top_mune);


        image = findViewById(R.id.image);

        msg1 = findViewById(R.id.msg1);
        msg2 = findViewById(R.id.msg2);
        msg3 = findViewById(R.id.msg3);
        msg4 = findViewById(R.id.msg4);
        msg5 = findViewById(R.id.msg5);
        msg6 = findViewById(R.id.msg6);
        msg7 = findViewById(R.id.msg7);
        msg8 = findViewById(R.id.msg8);
        msg9 = findViewById(R.id.msg9);
        msg10 = findViewById(R.id.msg10);
        msg11 = findViewById(R.id.msg11);
        msg12 = findViewById(R.id.msg12);
        tv_1 = findViewById(R.id.tv_1);
        tv_2 = findViewById(R.id.tv_2);
        tv_1.setOnClickListener(this);

        tv_2.setOnClickListener(this);

        setupViews();


    }


    private ViewGroup mMoreLayout;
    private List<ImageView> views = new ArrayList<ImageView>();
    private void setupViews() {
//        setContentView(R.layout.activity_main);

    }



    @Override
    public void onClick(View v) {

        switch (v.getId()) {

            case R.id.tv_1:
                finish();
                break;
            case R.id.tv_2:
                RefreshEvent event = new RefreshEvent();
                event.setType(RefreshEvent.SHOWFINISH);
                EventBus.getDefault().post(event);
                finish();
                break;
            case R.id.top_back:

                finish();
                break;

            case R.id.ll_lxcalc:
                RateCalcActivity.start(this);
                break;
            case R.id.ll_datecalc:
                DateCalcActivity.start(this);
                break;
            case R.id.ll_wyjcalc:
                PenaltyCalcActivity.start(this);
                break;
            case R.id.ll_carryout:
                CarryOutListActivity.start(this);
                break;
            default:
                break;
        }

//        final Object tag = v.getTag();      //通过之前setTag找到点击位置
//        if (tag != null) {
//            String department = (String) tag;
//            if("1".equalsIgnoreCase(department))
//            {
//                RateCalcActivity.start(this);
//            }else if("2".equalsIgnoreCase(department))
//            {
//                DateCalcActivity.start(this);
//            }else if("3".equalsIgnoreCase(department))
//            {
//                PenaltyCalcActivity.start(this);
//            }else if("4".equalsIgnoreCase(department))
//            {
////                ToolsActivity.start(getActivity());
//                CarryOutListActivity.start(this);
//            }
//        } // else ignored
    }


  public void getList() {
        if (BankruptcyApp.tokeninfo == null || BankruptcyApp.tokeninfo.getToken() == null) {

            return;
        }


        Map<String, String> parms = new HashMap<>();
        parms.put("userToken", getUserToken());
        parms.put("projectId", mProjectId);
        parms.put("pageNumber", pageNo + "");
        parms.put("pageSize", pageSize + "");
        if (committee ) parms.put("committee", committee + "");
        if (onlineStatus != null) parms.put("onlineStatus", onlineStatus + "");
        if (kindTax ) parms.put("kindTax", kindTax + "");
        if (kindGuarantee ) parms.put("kindGuarantee", kindGuarantee + "");
        if (kindOther ) parms.put("kindOther", kindOther + "");
        if (kindOrdinary   ) parms.put("kindOrdinary", kindOrdinary + "");
        if (minAmountDeclared != null && minAmountDeclared != 0f) parms.put("minAmountDeclared", minAmountDeclared + "");
        if (maxAmountDeclared != null && maxAmountDeclared != 0f) parms.put("maxAmountDeclared", maxAmountDeclared + "");
        if (minConfirmAmount != null && minConfirmAmount != 0f) parms.put("minConfirmAmount", minConfirmAmount + "");
        if (maxConfirmAmount != null && maxConfirmAmount != 0f) parms.put("maxConfirmAmount", maxConfirmAmount + "");
        if (processStatus != null) parms.put("processStatus", processStatus + "");

      parms.put("selectType", mSelectType + "");
      parms.put("creditorIds", mCreditorIds + "");

        Network.getAPIService()
                .creditorListStat(parms)
//                .getCreditorList(getUserToken(), projectId, committee, onlineStatus,
//                        kindTax, kindGuarantee, kindOther, kindOrdinary, minAmountDeclared,
//                        maxAmountDeclared, minConfirmAmount, maxConfirmAmount, processStatus,
//                        orderBy, orderColumn, pageNo, pageSize)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscriber<JsonObject>() {
                    @Override
                    public void onNext(JsonObject json) {
                        int code = json.get("code").getAsInt();
                        if (code != 0) {
                            super.onError(new Throwable(json.get("msg").getAsString()));
                            return;
                        } else {
                            JsonObject data = json.getAsJsonObject("data");
                            String str = data.get("total").toString();
                            msg1.setText(""+str+"人");

                            str = data.get("amountDeclaredTotal").toString();
                            msg2.setText(str+"元");

                            str = data.get("declareAmountPrincipal").toString();
                            msg3.setText(str+"元");

                            str = data.get("declareAmountInterest").toString();
                            msg4.setText(str+"元");

                            str = data.get("declareAmountOther").toString();
                            msg5.setText(str+"元");

                            str = data.get("confirmAmountTotal").toString();
                            msg6.setText(str+"元");

                            str = data.get("taxConfirmAmountTotal").toString();
                            msg7.setText(str+"元");

                            str = data.get("ordinaryMoney").toString();
                            msg8.setText(str+"元");

                            str = data.get("guaranteePriority").toString();
                            msg9.setText(str+"元");

                            str = data.get("otherPriorityMoney").toString();
                            msg10.setText(str+"元");

                            str = data.get("disconfirmationMoney").toString();
                            msg11.setText(str+"元");


                            str = data.get("undeterminedMoney").toString();
                            msg12.setText(str+"元");
                        }
                    }

                    @Override
                    public void onCompleted() {
                        super.onCompleted();
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);

                    }
                });
    }

}


